package com.wxzz.elearing.user.api.app;

import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.user.dto.EnterpriseApplyDto;
import com.wxzz.elearing.user.entity.EnterpriseApply;
import com.wxzz.elearing.user.service.IEnterpriseApplyService;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/wx-enterprise-apply")
@Api(tags = "企业入驻接口")
public class WxEnterpriseApplyController {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Autowired
    private IEnterpriseApplyService enterpriseApplyService;

    @ApiOperation(value = "企业入驻申请(小程序)", notes = "企业入驻申请(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "saveEnterpriseApply", method = RequestMethod.POST)
    public ReturnVO saveEnterpriseApply(@RequestHeader String token, @RequestBody EnterpriseApply enterpriseApply) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        enterpriseApply.setWxUserId(jsonObject.getLong("id"));
        return enterpriseApplyService.saveEnterpriseApply(enterpriseApply);
    }

    @ApiOperation(value = "查询企业申请审核状态(小程序)", notes = "查询企业申请审核状态(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "selectStatus", method = RequestMethod.POST)
    public ReturnVO selectStatus(@RequestHeader String token) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return enterpriseApplyService.selectStatus(jsonObject.getLong("id"));
    }

}
